﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace Nightlife.Models
{
    public partial class NightlifeDB
    {
        public User GetUser(int id)
        {
            return db.Users.FirstOrDefault(u => u.ID == id);
        }

        public User GetUser(string username)
        {
            return db.Users.FirstOrDefault(u => u.Username == username);
        }

        public User GetUser(MembershipUser memUser)
        {
            return db.Users.FirstOrDefault(u => u.Username == memUser.UserName);
        }

        public List<User> GetAllUsers()
        {
            return db.Users.ToList();
        }

        public List<User> GetFriends(int id)
        {
            User user = GetUser(id);
            return (from u in db.Users select u).ToList();
        }

        public bool Add(User user)
        {
            if (db.Users.FirstOrDefault(u => u.Username == user.Username) == null)
                return false;
            db.Users.Add(user);
            db.SaveChanges();
            return true;
        }

    }
}